﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Transcend.FileUploader.Entity
{
	/// <summary>
	/// dsitem 描述类
	/// </summary>
	public class DocCategory
	{

		public decimal Id { get; set; }

		/// <summary>
		/// 显示顺序
		/// </summary>
		public int RowNo { get; set; }

		/// <summary>
		/// 文档类型ID 默认 0
		/// </summary>
		public decimal CredId { get; set; }

		/// <summary>
		/// 分类名称
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// 文档宗ID
		/// </summary>
		public decimal InstId { get; set; }

		/// <summary>
		/// 文档类型编号 适用于使用模板生成文档类型列表，文档类型，默认 0
		/// </summary>
		public decimal CredType { get; set; }

		/// <summary>
		/// 分类下文档页数 默认 0
		/// </summary>
		public int PageNum { get; set; }

		/// <summary>
		/// 份数 默认 0
		/// </summary>
		public int Copies { get; set; }

		/// <summary>
		/// 默认 0
		/// </summary>
		public int ScanNum { get; set; }

        /// <summary>
        /// 业务步骤ID
        /// </summary>
        public decimal STEP_ID { get; set; }

		/// <summary>
		/// 是否双面
		/// </summary>
		public int IsDouble { get; set; }

		/// <summary>
		/// 关键字
		/// </summary>
		public string Keyword { get; set; }

		/// <summary>
		/// 新增时间 默认为DateTime.MinValue
		/// </summary>
		public DateTime CreateTime { get; set; }

		/// <summary>
		/// 备注
		/// </summary>
		public string Notes { get; set; }

		/// <summary>
		/// 父类型Id
		/// </summary>
		public decimal ParentItemId { get; set; }

		/// <summary>
		/// 所属文档
		/// </summary>
		public DocInstance Document { get; set; }

		/// <summary>
		/// 设置/获取当前分类下的文档信息
		/// </summary>
		public List<DocPage> DocPage
		{
			get;
			private set;
		}

		public DocCategory()
			: this(0, 0, string.Empty, 0)
		{ }

		public DocCategory(decimal itemid, int rowno, string credname, decimal instid)
			: this(itemid, rowno, 0, credname, instid)
		{ }

		public DocCategory(decimal itemid, int rowno, decimal credid, string credname, decimal instid)
			: this(itemid, rowno, credid, credname, instid, 0, 1, 0, 0, 0, 0, string.Empty, DateTime.Now, string.Empty, 0)
		{ }

		public DocCategory(decimal id, int rowno, decimal credid, string credname, decimal instid, decimal credtype, int pagenum, int copies, int scannum, decimal businessid, int isdouble, string keyword, DateTime createtime, string notes, decimal parentitemid)
		{
			Id = id;
			RowNo = rowno;
			CredId = credid;
			Name = string.IsNullOrEmpty(credname) ? "默认分类" : credname;
			InstId = instid;
			CredType = credtype;
			PageNum = pagenum;
			Copies = copies;
			ScanNum = scannum;
			IsDouble = isdouble;
			Keyword = keyword;
			CreateTime = createtime;
			Notes = notes;
			ParentItemId = parentitemid;
			DocPage = new List<DocPage>(1);
		}

		/// <summary>
		/// 向分类添加文档页
		/// </summary>
		public DocPage Add(DocPage page)
		{
			if (page == null) return page;
			page.ItemId = Id;
			page.Category = this;
			DocPage.Add(page);
			return page;
		}

		/// <summary>
		/// 向分类添加文档页
		/// </summary>
		/// <returns></returns>
		public DocPage Add(decimal imgno, int pageno, string rawfilename, decimal userid)
		{
			DocPage page = new DocPage(imgno, Id, pageno, rawfilename, userid);
			return Add(page);
		}

		/// <summary>
		/// 向分类添加文档页集合
		/// </summary>
		/// <param name="pages"></param>
		public void Add(List<DocPage> pages)
		{
			if (pages == null) return;
			foreach (DocPage p in pages)
			{
				p.Category = this;
				Add(p);
			}
		}

		public override bool Equals(object obj)
		{

			if (obj != null && obj is DocCategory)
			{
				DocCategory c = (DocCategory)obj;
				if (!string.IsNullOrEmpty(this.Name) && this.Name.Equals(c.Name, StringComparison.Ordinal))
				{
					return (Document != null && Document.Equals(c.Document));
				}
			}
			return false;
		}
	}
}
